package public

import (
	"github.com/hwcer/cosgo/registry"
	"github.com/hwcer/yyds/context"
	"server/game/cache"
	"server/share/config"
)

func init() {
	Register(&updateRole{})
}

type updateRole struct {
}

func (this *updateRole) Caller(node *registry.Node, handle *context.Context) interface{} {
	f := node.Method().(func(*updateRole, *context.Context) interface{})
	return f(this, handle)
}

func (*updateRole) GetLevelReward(c *context.Context) any {
	roleDoc := cache.GetRole(c.Player.Updater)
	roleAll := roleDoc.All()
	if roleAll.LReward >= roleAll.Lv {
		return false
	}
	for i := roleAll.LReward; i <= roleAll.Lv; i++ {
		if playerExp := config.Data.PlayerExp[i]; playerExp != nil && playerExp.LevelBonus > 0 {
			c.Player.Add(playerExp.LevelBonus, 1)
		}
	}
	roleDoc.Set("lReward", roleAll.Lv)
	return true
}
